﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ZLFMSTInputDialog
{
    public partial class InputBox_Str : Form
    {
        bool fIsIPAddress = false;
        public InputBox_Str(string fDefaultStr, string fCaption, string fTitle,bool fIsIPAddressX =false)
        {
            InitializeComponent();
            textBox1.Text = fDefaultStr;
            label1.Text = fCaption;
            Text = fTitle;
            fIsIPAddress = fIsIPAddressX;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IPAddress fIP;
            if ((!fIsIPAddress) || ((fIsIPAddress && IPAddress.TryParse(textBox1.Text, out fIP))))
            {
                this.DialogResult = DialogResult.OK;
                Close();
            }
        }
        public static bool InputStrBox(ref string fValue,  string fCaption, string fTitle)
        {
            InputBox_Str fInputForm = new InputBox_Str(fValue, fCaption, fTitle);
            if (fInputForm.ShowDialog() == DialogResult.OK)
            {
                fValue = fInputForm.textBox1.Text;
                return true;
            }
            return false;
        }

        public static bool InputStrBox(ref string fValue, string fCaption)
        {            
            return InputStrBox(ref  fValue,  fCaption,"输入字符串");
        }
    }
}
